package youleche.com.business;

import java.sql.Connection;
import java.util.List;

import youleche.com.common.IDFactory;
import youleche.com.connection.ConnectionFactory;
import youleche.com.factory.DaoFactory;
import youleche.com.idao.IPagelimit;
import youleche.com.model.MPagelimit;

/**
 * 页面权限访问
 * @author Administrator
 *
 */
public class BPagelimit {
	/**
	 * 数据库连接
	 */
	private Connection con = null;
	
	/**
	 * 处理器
	 */
	private IPagelimit handler = null;
	
	/**
	 * 构造器
	 */
	public BPagelimit(){
		this.handler =DaoFactory.getDPageLimit();
	}
	
	/**
	 * 添加权限页面
	 * @param con 数据库连接
	 * @param pagelimit 页面权限信息
	 * @return 返回影响的行数
	 * @throws Exception 异常
	 */
	public int addPageLimit(MPagelimit pagelimit)
			throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheWriteConnection();
			return this.handler.addPageLimit(this.con, pagelimit);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	
	/**
	 * 判断是否存在该页面权限节点
	 * @param pageName 节点名称
	 * @return 是否存在  true-存在
	 * @throws Exception 异常
	 */
	public boolean isExistPageByPageName(String pageName)
			throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheReadConnection();
			return this.handler.isExistPageByPageName(this.con, pageName);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	
	/**
	 * 得到所有权限节点
	 * @return 返回所有节点
	 * @throws Exception 异常
	 */
	public List<MPagelimit> getAllPageLimitNodes()
			throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheReadConnection();
			return this.handler.getAllPageLimitNodes(this.con);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	
	/**
	 * 通过id更新节点
	 * @param id id
	 * @return 返回影响的行数
	 * @throws Exception 异常
	 */
	public int updateNodeById(String id) throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheWriteConnection();
			return this.handler.updateNodeById(this.con, id);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
}
